﻿using AllInOnePluginBL.Helpers;
using AllInOnePluginBL.SiteInfoScrappers;

namespace AllInOnePluginBL.Rules
{
    /// <summary>
    /// Summary description for ExtractMovieInfoRule
    /// </summary>
    public class ExtractMovieInfoRule : IRule
    {
        public void ApplyRule(PluginDB.PluginVideoInfo pluginVideoInfo)
        {
            //If the movie is not of movies type then exit
            if (pluginVideoInfo.IsTVShow) return;

            var videoInformation = TorecNetScraper.GetVideoInformation(pluginVideoInfo.HebrewVideoName);
            if(videoInformation.IsValid)
            {
                if(!Utils.IsContainsHebrew(pluginVideoInfo.HebrewVideoName))
                {
                    pluginVideoInfo.HebrewVideoName = videoInformation.Name;
                }

                if(string.IsNullOrEmpty(pluginVideoInfo.Plot))
                {
                    pluginVideoInfo.Plot = videoInformation.Plot;
                }

                if(string.IsNullOrEmpty(pluginVideoInfo.ImageUrl))
                {
                    pluginVideoInfo.ImageUrl = videoInformation.FanartUrl;
                }
            }
        }
    }
}